﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace GraphDrawer {
	public partial class Source : UserControl {
		public readonly ImportNetwork import;
		public readonly GenerateNetwork generator;
		public readonly DatabaseNetworkSelector database;

		public Type sourceMethod;
		public event RoutedEventHandler isSelectedSource;
		
		private IWizardController wc;
		private static RoutedEventHandler popUpOk;

		public Source(IWizardController wc, GraphProvider.GraphProviderServiceSoapClient graphProvider) {
			InitializeComponent();
			
			this.wc = wc;
			import = new ImportNetwork(wc);
			generator = new GenerateNetwork(graphProvider, wc);
			database = new DatabaseNetworkSelector(graphProvider, wc);
		}

		public void Import_Click(object sender, RoutedEventArgs e) {
			//App.Current.Host.Content.IsFullScreen = false;

			sourceMethod = import.GetType();
			popUpOk = new RoutedEventHandler(PopUp_OK);
			wc.PopUp.OK += popUpOk;
			wc.PopUp.AddUserControl(import);
			wc.PopUp.Visibility = Visibility.Visible;
		}

		public void Generate_Click(object sender, RoutedEventArgs e) {
			App.Current.Host.Content.IsFullScreen = false;

			sourceMethod = generator.GetType();
			popUpOk = new RoutedEventHandler(PopUp_OK);
			wc.PopUp.OK += popUpOk;
			wc.PopUp.AddUserControl(generator);
			wc.PopUp.Visibility = Visibility.Visible;
		}

		private void Database_Click(object sender, RoutedEventArgs e) {
			//App.Current.Host.Content.IsFullScreen = false;
			
			sourceMethod = database.GetType();
			popUpOk = new RoutedEventHandler(PopUp_OK);
			wc.PopUp.OK += popUpOk;
			wc.PopUp.AddUserControl(database);
			database.Init();
			wc.PopUp.Visibility = Visibility.Visible;
		}

		public void Quest_Click(object sender, RoutedEventArgs e) {
			App.Current.Host.Content.IsFullScreen = false;

			//TODO: Diplay popup "This future is not active yet. We are still working to bring it to you as soon as possible."
		}

		void PopUp_OK(object sender, RoutedEventArgs e) {
			wc.PopUp.OK -= popUpOk;
			isSelectedSource.Invoke(sender, e);
		}
	}
}
